package com.ctshk.sapp.bus.controller;


import java.util.List;

import javax.validation.Valid;

import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.ctshk.common.annotations.OperationLogAnnotation;
import com.ctshk.common.dto.Result;
import com.ctshk.common.enums.OperationLogModel;
import com.ctshk.common.enums.OperationLogType;
import com.ctshk.common.model.PageResponse;
import com.ctshk.common.utils.individual.conversion.BatchStrategyReq;
import com.ctshk.common.utils.individual.conversion.dto.BatchStrategyDto;
import com.ctshk.common.web.support.BaseController;
import com.ctshk.rpc.bus.dto.BusProductDetailDTO;
import com.ctshk.rpc.bus.dto.BusProductManagePageDTO;
import com.ctshk.rpc.bus.dto.BusProductStrategyDTO;
import com.ctshk.rpc.bus.req.BusProductDetailByStrategyReq;
import com.ctshk.rpc.bus.req.BusProductQueryReq;
import com.ctshk.rpc.bus.req.BusProductStrategyReq;
import com.ctshk.rpc.bus.req.BusProductStrategySaveBatchReq;
import com.ctshk.rpc.bus.service.IBusProductStrategyService;
import com.ctshk.sapp.bus.convertor.Convertor;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;

/**
 * <p>
 * 巴士产品加幅策略 前端控制器
 * </p>
 *
 * @author 彭柳霖
 * @since 2021-02-19
 */
@Api(value="产品中心-巴士上架设置", tags="产品中心-巴士上架设置")
@RestController
@RequestMapping("/bus-product-strategy")
public class BusProductStrategyController extends BaseController {

    @DubboReference
    private IBusProductStrategyService busProductStrategyService;


    @ApiOperation(value = "产品中心-巴士票管理列表查询", notes = "产品中心-巴士票管理列表查询")
    @PostMapping(value = "/query-list")
    public Result<PageResponse<BusProductManagePageDTO>> queryList(@RequestBody BusProductQueryReq req) {
        return busProductStrategyService.queryList(req, getCurrentUser());
    }

    @ApiOperation(value = "巴士产品上架加幅设置-保存加幅策略", notes = "巴士产品上架加幅设置-保存加幅策略")
    @OperationLogAnnotation(operModul = OperationLogModel.TICKET, operType = OperationLogType.ADD, operTitle = "巴士产品上架加幅设置-保存加幅策略", operDesc = "巴士产品上架加幅设置-保存加幅策略")
    @PostMapping("/save")
    public Result save(@RequestParam("busProductId") Long busProductId, @Valid @RequestBody List<BusProductStrategyReq> busProductStrategyReqList) {
        Long userId = getCurrentUser(getRequest()).getId();
        return busProductStrategyService.save(busProductId, busProductStrategyReqList, userId);
    }


    @ApiOperation(value = "巴士加幅策略-批量保存加幅策略", notes = "巴士加幅策略-批量保存加幅策略")
    @OperationLogAnnotation(operModul = OperationLogModel.TICKET, operType = OperationLogType.ADD, operTitle = "巴士加幅策略-批量保存加幅策略", operDesc = "巴士加幅策略-批量保存加幅策略")
    @PostMapping("/save/batch")
    public Result saveBatch(@RequestBody @Valid BatchStrategyReq batchStrategyReq) {
        Long userId = getCurrentUser(getRequest()).getId();
        BusProductStrategySaveBatchReq busProductStrategySaveBatchReq = Convertor.frontToBusProduct(batchStrategyReq);
        return busProductStrategyService.saveBatch(busProductStrategySaveBatchReq, userId);
    }


    @ApiOperation(value="根据产品id查询产品加幅详情信息", notes="根据产品id查询产品加幅详情信息")
    @OperationLogAnnotation(operModul = OperationLogModel.TICKET, operType = OperationLogType.QUERY, operTitle = "根据产品id查询产品加幅详情信息", operDesc = "根据产品id查询产品加幅详情信息")
    @GetMapping("/queryByProductId")
    public Result<BatchStrategyDto> queryByProductId(@RequestParam(value = "productId", required = true) Long productId) {
         List<BusProductStrategyDTO>  list = busProductStrategyService.queryByProductId(productId);
         return Result.success(Convertor.busProductToFront(list));
    }

    @ApiOperation(value = "巴士-产品中心-查看详情", notes = "巴士-产品中心-查看详情)")
    @OperationLogAnnotation(operModul = OperationLogModel.TICKET, operType = OperationLogType.QUERY, operTitle = "火车票-产品中心-查看详情", operDesc = "火车票-产品中心-查看详情")
    @PostMapping("/detail")
    public Result<BusProductDetailDTO> getDetail(@RequestBody @Valid BusProductDetailByStrategyReq req) {
        return busProductStrategyService.selectDetail(req);
    }
}
